<!DOCTYPE HTML>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>

<dialog id="modal-1">
  <div id="aria-modal-1" role="button" aria-modal="true">
  </div>
  <div id="aria-modal-2" role="dialog" aria-modal="false">
  </div>
  <div id="aria-modal-3" role="dialog" aria-modal="true">
  </div>
  <div id="aria-modal-4" role="alertdialog" aria-modal="true">
  </div>
  <dialog id="modal-2">Closed Dialog</dialog>
  <dialog open id="modal-3">Open Dialog</dialog>
  <dialog open id="modal-4" aria-modal="true">Open with aria-modal</dialog>
</dialog>

<script>
document.getElementById('modal-1').showModal();

function axElementById(id) {
    return accessibilityController.accessibleElementById(id);
}

test(function(t) {
    var axAriaModal1 = axElementById("aria-modal-1");
    assert_equals(axAriaModal1.isModal, false);
}, "A button can't be modal");

test(function(t) {
    var axAriaModal2 = axElementById("aria-modal-2");
    assert_equals(axAriaModal2.isModal, false);
}, "An ARIA dialog with aria-modal false is not modal");

test(function(t) {
    var axAriaModal3 = axElementById("aria-modal-3");
    assert_equals(axAriaModal3.isModal, true);
}, "An ARIA dialog with aria-modal true is modal");

test(function(t) {
    var axAriaModal4 = axElementById("aria-modal-4");
    assert_equals(axAriaModal4.isModal, true);
}, "An ARIA alertdialog with aria-modal true is modal");

test(function(t) {
    var axModal1 = axElementById("modal-1");
    assert_equals(axModal1.isModal, true);
}, "An HTML dialog is modal after calling showModal() on it");

test(function(t) {
    var axModal2 = axElementById("modal-2");
    assert_equals(axModal2.isModal, false);
    assert_equals(axModal2.isIgnored, true);
}, "A closed HTML dialog has no accessibility node");

test(function(t) {
    var axModal3 = axElementById("modal-3");
    assert_equals(axModal3.isModal, false);
}, "An open HTML dialog is not modal");

test(function(t) {
    var axModal4 = axElementById("modal-4");
    assert_equals(axModal4.isModal, true);
}, "An open HTML dialog with aria-modal=true is modal");

</script>
